using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraBars;
using Han.Util;
using System.Linq;

namespace Han
{
    public partial class rfrmMain : DevExpress.XtraBars.Ribbon.RibbonForm
    {
        public rfrmMain()
        {
            InitializeComponent();
            Util.FrmLogin loginForm = new FrmLogin();
            if (loginForm.ShowDialog() == System.Windows.Forms.DialogResult.Cancel)
                ribbon.Enabled = false;
        }

        Forms.frmDukkanGiris frmDukkanGiris;
        Forms.frmKiraciGiris frmKiraciGiris;
        Forms.frmKontrat frmKontrat;
        Forms.frmMasrafGirisi frmMasrafGiris;
        Forms.frmOdemeGirisi frmOdemeGirisi;
        Forms.frmKontratTakip frmKontratTakip;

        private void ShowForm(Form frm)
        {

            if (this.MdiChildren.Contains(frm))
                frm.BringToFront();

            frm.MdiParent = this;
            frm.Show();
        }
        private void bbiDukkan_ItemClick(object sender, ItemClickEventArgs e)
        {
            if (frmDukkanGiris == null)
                frmDukkanGiris = new Han.Forms.frmDukkanGiris();

            ShowForm(frmDukkanGiris);
        }

        private void bbiKiraci_ItemClick(object sender, ItemClickEventArgs e)
        {
            if (frmKiraciGiris == null || frmKiraciGiris.IsDisposed)
                frmKiraciGiris = new Han.Forms.frmKiraciGiris();

            ShowForm(frmKiraciGiris);

        }

        private void bbiKontrat_ItemClick(object sender, ItemClickEventArgs e)
        {
            if (frmKontrat == null||frmKontrat.IsDisposed )
                frmKontrat = new Han.Forms.frmKontrat();

            ShowForm(frmKontrat);
        }

        private void bbiMasraf_ItemClick(object sender, ItemClickEventArgs e)
        {
            if (frmMasrafGiris == null || frmMasrafGiris.IsDisposed)
                frmMasrafGiris = new Han.Forms.frmMasrafGirisi();

            ShowForm(frmMasrafGiris);
        }

        private void bbiOdeme_ItemClick(object sender, ItemClickEventArgs e)
        {
            if (frmOdemeGirisi == null || frmOdemeGirisi.IsDisposed)
                frmOdemeGirisi = new Han.Forms.frmOdemeGirisi();

            ShowForm(frmOdemeGirisi);
        }

        private void bBtnYeni_ItemClick(object sender, ItemClickEventArgs e)
        {
            var form = this.ActiveMdiChild as iAddNew;

            if (form != null)
                form.AddNew();

        }

        private void bBtnKaydet_ItemClick(object sender, ItemClickEventArgs e)
        {
            var form = this.ActiveMdiChild as iSaveChange;

            if (form != null)
                form.SaveChange();

        }

        private void rfrmMain_Load(object sender, EventArgs e)
        {
            rfrmMain_MdiChildActivate(this, new EventArgs()); 
        }
                
        private void rfrmMain_MdiChildActivate(object sender, EventArgs e)
        {
            bBtnKaydet.Visibility = (this.ActiveMdiChild is iSaveChange) ? BarItemVisibility.Always : BarItemVisibility.Never;
            bBtnYeni.Visibility = (this.ActiveMdiChild is iAddNew) ? BarItemVisibility.Always : BarItemVisibility.Never;

            bBtnResimEkle.Visibility = (this.ActiveMdiChild is iAddImage) ? BarItemVisibility.Always : BarItemVisibility.Never;
            bbtnMasrafEkle.Visibility = (this.ActiveMdiChild is iAddMasraf) ? BarItemVisibility.Always : BarItemVisibility.Never;
            bBtnOdemeEkle.Visibility = (this.ActiveMdiChild is iAddOdeme) ? BarItemVisibility.Always : BarItemVisibility.Never;

            rpGroupEkle.Visible = ((this.ActiveMdiChild is iAddImage) || (this.ActiveMdiChild is iAddMasraf) || (this.ActiveMdiChild is iAddOdeme));
            rpGroupDuzenle.Visible = rpgDuzenle1.Visible = ((this.ActiveMdiChild is iSaveChange) || (this.ActiveMdiChild is iAddNew));
        }

        private void barButtonItem3_ItemClick(object sender, ItemClickEventArgs e)
        {
            if (frmKontratTakip == null || frmKontratTakip.IsDisposed)
                frmKontratTakip = new Han.Forms.frmKontratTakip();

            ShowForm(frmKontratTakip);
        }

        private void bBtnResimEkle_ItemClick(object sender, ItemClickEventArgs e)
        {
            var frm = this.ActiveMdiChild as iAddImage;

            frm.AddImage();
        }

        private void barButtonItem4_ItemClick(object sender, ItemClickEventArgs e)
        {
            var frm = this.ActiveMdiChild as iAddMasraf;
            frm.AddMasraf(); 
        }

        private void barButtonItem5_ItemClick(object sender, ItemClickEventArgs e)
        {
            var frm = new Forms.frmKontratWizard();
            frm.ShowDialog(); 
        }

        private void bBtnOdemeEkle_ItemClick(object sender, ItemClickEventArgs e)
        {
            (this.ActiveMdiChild as iAddOdeme).AddOdeme(); 
        }


    }
}